Ccay.Module.define("Ccay.example.neiqian", function(page, $S) {

Ccay.UI.IGrid.Factory.EventBinder.bindClick = function (grid, op) {
            if(op.handler.click.length)
                // 单元格点击事件注册
                grid.getContent().delegate('[eno]', "click", function (e) {
                    var target = $(this), eNo = target.attr("eno"), isExecEno;
                    if (target.hasClass("grid-cell")) {
                        var col = grid.getColumnOp(target), tr = grid.getCellRow(target);
                        if(!op.onCellClick || op.onCellClick.call(grid, grid.cellData(target), grid.getRowData(tr) , target, tr, col._i, grid.getRowIndex(tr), col, grid, e) !== false) {
                            // 设置表头点击事件
                            if (target.parent().parent().hasClass("igrid-head")) {
                                op.onHeadClick && op.onHeadClick.call(grid, e, target, col, grid);
                            }
                            isExecEno = true;
                        }
                    } else {
                        isExecEno = true;
                    }
                    if (isExecEno) {
                        if(!op._disabled && (!op._readonly || eNo != "edit") && eNo && !target.hasClass('disabled')) {
                            var trigger = op.handler.click.get(eNo);
                            trigger && trigger(e, target, grid);
                        }
                    }
                    e.stopPropagation();
                });
            // 设置触发行点击事件
            grid.getBodyTable().delegate("tr.grid-row", "click", function(e) {
                var tr = $(this), td = $(e.target), col = grid.getColumnOp(td);
                op.onRowClick && op.onRowClick.call(grid, grid.cellData(td), grid.getRowData(tr), td, tr, col._i, grid.getRowIndex(tr), col, grid, e);
                if(!op._disabled && !tr.hasClass('igrid-actived') && !tr.hasClass('row-noselect'))
                {
                    if (op._hTr) {
                        op._hTr.removeClass('igrid-actived');
                        // 移除上一行的鼠标标示
                        op._hTr.removeData("focusin");
                    }
                    tr.addClass('igrid-actived');
                    op._hTr = tr;
                }
            });
            // 设置mouseover事件
            grid.getBodyTable().delegate("td.grid-cell", "mouseover", function (e) {
                var td = $(this), col = grid.getColumnOp(td), tr = grid.getCellRow(td);
                op.onMouseOver && op.onMouseOver.call(grid, grid.cellData(td), grid.getRowData(tr), td, tr, col._i, grid.getRowIndex(tr), col, grid, e);
            });
        };

var gridOption2 = {
		onRowClick:function(val,rowdata,td, tr,colId,rowId,col, grid, e){
		if(!tr.data("inDivId") && $(e.srcElement).parents("[inTr]").length==0){
			tr.data("inDivId","inDivId_"+rowId) ;
			var inTd =   $.create("td").attr("colspan",tr.children().length).addClass("grid-cell");
			var inTr =  $.create("tr","",tr.data("inDivId")).attr("inTr","");
			var inGridDiv = $.create("div", "", "inGridDiv_"+rowId);
			var inDiv = $.create("div" ).css({"margin":"5px"});		
			inDiv.append("<div class='ccay-grid-toolbar'><input id='inGridDiv_"+rowId+"_addBut'  value='insert' type='button' /></div>")
			inTr.append(inTd.append(inDiv.append(inGridDiv)));
			tr.after(inTr);
			
			var gridOption3 = {
				pagerOp:{
					pageSizes:[2]
				},
				editMode: true,
				columns: [
					 {field: 'name', width: 80, header: "ccay.common.label.name"}, 
					 {field: 'sex', width: 70, header: "Sex", type: 'bool', sortable: false},
					 {field: 'age', width: 70, header: "Age", cssName: "center", sort: 'desc', resizable: false}],
				ajax:{
						url: 'services/ccay/demo/student/list/page/2/${curPage}/${orderBy}'
					},
				operation: {
							insert:{
										
									btn: "#inGridDiv_"+rowId+"_addBut",
									copy: true
								}
				}				
			}
			$("#inGridDiv_"+rowId).igrid(gridOption3);     	
		}else if(tr.data("inDivId")){
			$("#"+tr.data("inDivId")).toggle();
		}
		
		
	},
		columns: [

		 {field: 'name', width: 80, header: "ccay.common.label.name"}, 
		 
		
		 {field: 'sex', width: 70, header: "Sex", type: 'bool', sortable: false},
		 
		 
		 {field: 'age', width: 70, header: "Age", cssName: "center", sort: 'desc', resizable: false},
		 
		
		 {field: 'birthday', width: 90, header: "Birthday", type: 'date'}
		],
		ajax:{
			url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
		},
		operation: {
				insert:{
							
						btn: "#addBut",
						copy: true
					}
		}
	};

	$("#igridDemo2").igrid(gridOption2);  
})